Skip to content

fix(CodeBlock): handle ReactNode children with angle-bracket placeholders#950

Open
mneedham wants to merge 7 commits into
ClickHouse:mainfrom
mneedham:fix/codeblock-react-node-children
Open

fix(CodeBlock): handle ReactNode children with angle-bracket placeholders#950
mneedham wants to merge 7 commits into
ClickHouse:mainfrom
mneedham:fix/codeblock-react-node-children

Conversation

@mneedham
Copy link
Copy Markdown
Collaborator

@mneedham mneedham commented Mar 25, 2026

Summary

  • Changed children prop type from string to ReactNode in CodeBlock.types.ts
  • Added nodeToString() helper that recursively converts ReactNode to a plain string, reconstructing <tag> syntax for React element nodes
  • All internal uses of children as a string now go through nodeToString(children)

Problem

When code content contains <placeholder> style text (e.g. shell scripts with <project_id>, <email>), JSX parses those as React elements rather than raw text. SyntaxHighlighter then receives objects instead of a string and renders [object Object] throughout the block.

Test plan

  • Pass a code block with <placeholder> style content and verify it renders literally
  • Verify $VARIABLE style content still renders as-is
  • Verify copy button copies the correct plain-text string
  • Verify existing SQL/bash/JSON syntax highlighting still works

🤖 Generated with Claude Code


Note

Low Risk
Localized UI component change with backward-compatible string children; minor public API widening and dev-hook behavior only.

Overview
CodeBlock now accepts ReactNode children and normalizes them with a new nodeToString() helper before syntax highlighting and clipboard copy, so angle-bracket placeholders (e.g. <project_id>) that JSX would otherwise turn into elements no longer show as [object Object]. Copy/onCopy use the same plain-text string. Unit tests cover literals, $VAR, placeholders, and copy behavior. A minor changeset documents the package fix.

Pre-commit circular dependency checks run only when RUN_DEPS_CHECK=1 (README tip added). The skott script redirects stdin from /dev/null to reduce reported hangs on macOS.

Reviewed by Cursor Bugbot for commit 340a954. Bugbot is set up for automated code reviews on this repo. Configure here.

…ders

JSX parses <placeholder> style content as React elements, causing
SyntaxHighlighter to receive objects instead of strings and render
[object Object]. Accept ReactNode children and stringify them,
reconstructing <tag> syntax for element nodes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 25, 2026

🦋 Changeset detected

Latest commit: 340a954

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clickhouse/click-ui Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown
Contributor

@punkbit punkbit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mneedham thanks for your contribution, mind add the missing changeset? Check https://github.com/clickHouse/click-ui?tab=readme-ov-file#add-a-new-changeset

motsc and others added 3 commits March 25, 2026 14:43
…use#952)

* chore: 🤖 make circular dependency check on commit as opt-in

* refactor: 💡 make input not expected

* docs: 📝 how to opt-in for circular-dependency

* chore: 🤖 remove line break

* chore: 🤖 add note about redirecting stdin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants